package ro.gillardon.beans;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "locationView", eager = true)
@SessionScoped
public class LocationView {

  private List<String> allLocations;
  private List<String> from;
  private List<String> to;

  private String fromSelected;
  private String toSelected;

  /**
   * Instantiates a new SubsistenceView.
   */
  public LocationView() {
    //constructor without parameters
  }

  @PostConstruct
  public void init() {
    this.allLocations = new ArrayList<String>();
    this.allLocations.add("Munchen");
    this.allLocations.add("Cluj");
    this.allLocations.add("Bretten");
    this.from = new ArrayList<String>(this.allLocations);
    this.to = new ArrayList<String>(this.allLocations);
  }

  public String getFromSelected() {
    return this.fromSelected;
  }

  public void setFromSelected(final String fromSelected) {
    this.fromSelected = fromSelected;
  }

  public String getToSelected() {
    return this.toSelected;
  }

  public void setToSelected(final String toSelected) {
    this.toSelected = toSelected;
  }

  public List<String> getFrom() {
    return this.from;
  }

  public void setFrom(final List<String> from) {
    this.from = from;
  }

  public List<String> getTo() {
    return this.to;
  }

  public void setTo(final List<String> to) {
    this.to = to;
  }

  public void onFromChange() {
    if (this.fromSelected != null && !"".equals(this.fromSelected)) {
      this.to = new ArrayList<String>(this.allLocations);
      this.to.remove(this.fromSelected);
    }
  }

}
